/* eslint-disable */
export default {
	//格式化时间（苹果时间只支持 / 写法）
	formattingTime(val) {
		return val.replace(/-/g, "/");
	},

	//精确除法
	accDiv(arg1, arg2) {
		if(!arg1 || !arg2) return;
		var t1 = 0,
			t2 = 0,
			r1, r2;
		try {
			t1 = arg1.toString().split(".")[1].length;
		} catch (e) {}

		try {
			t2 = arg2.toString().split(".")[1].length;
		} catch (e) {}


		r1 = Number(arg1.toString().replace(".", ""));
		r2 = Number(arg2.toString().replace(".", ""));
		return (r1 / r2) * Math.pow(10, t2 - t1);
	},

	//精确乘法
	accMul(arg1, arg2) {
		if(!arg1 || !arg2) return;
		var m = 0,
			s1 = arg1.toString(),
			s2 = arg2.toString();
		try {
			m += s1.split(".")[1].length;
		} catch (e) {}

		try {
			m += s2.split(".")[1].length;
		} catch (e) {}

		return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
	},

	//精确加法
	accAdd(arg1, arg2) {
		var r1, r2, m;
		try {
			r1 = arg1.toString().split(".")[1].length;
		} catch (e) {
			r1 = 0
		}

		try {
			r2 = arg2.toString().split(".")[1].length;
		} catch (e) {
			r2 = 0
		}
		m = Math.pow(10, Math.max(r1, r2));
		return (arg1 * m + arg2 * m) / m;
	},

	//精确减法
	accReduce(arg1, arg2) {
		var r1, r2, m;
		try {
			r1 = arg1.toString().split(".")[1].length;
		} catch (e) {
			r1 = 0
		}

		try {
			r2 = arg2.toString().split(".")[1].length;
		} catch (e) {
			r2 = 0
		}
		m = Math.pow(10, Math.max(r1, r2));
		return (arg1 * m - arg2 * m) / m;
	},

	//截取位数
	TimeDigit(value, n, m) {
		if(!value) return;
		return value.substring(n, m);
	},

	//取N位小数
	Decimal(value, n) {
		if(!value) return;
		var m = Math.pow(10, n);
		if (value.toString().indexOf('-') != -1) {
			return Math.ceil(value * m) / m;
		} else {
			return Math.floor(value * m) / m;
		}
	},
	
	
	// 执行解密
	runDataDecryption(string) {
	    var key = 'AoQ@jlZr!7f#r7y0S';
	    var len = key.length;
	    var code = '';
	    // 解密数据
	    string = this.dataDecryption(string);
	    for (let i = 0; i < string.length; i++) {
	       let k = i % len;
	        code += String.fromCharCode(string.charCodeAt(i) ^ key.charCodeAt(k));
	    }
	
	    return code;
	},
	
	// 解密方式
	dataDecryption(data) {
	    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
	        ac = 0,
	        dec = "",
	        tmp_arr = [];
	    if (!data) {
	        return data;
	    }
	    data += '';
	    do {
	        // unpack four hexets into three octets using index points in b64
	        h1 = b64.indexOf(data.charAt(i++));
	        h2 = b64.indexOf(data.charAt(i++));
	        h3 = b64.indexOf(data.charAt(i++));
	        h4 = b64.indexOf(data.charAt(i++));
	        bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
	        o1 = bits >> 16 & 0xff;
	        o2 = bits >> 8 & 0xff;
	        o3 = bits & 0xff;
	        if (h3 == 64) {
	            tmp_arr[ac++] = String.fromCharCode(o1);
	        } else if (h4 == 64) {
	            tmp_arr[ac++] = String.fromCharCode(o1, o2);
	        } else {
	            tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
	        }
	    } while (i < data.length);
	    dec = tmp_arr.join('');
	    return dec;
	},
	
	//获取对应字典类型数据
	getDataDict(value){
		let arr = []
		let data = uni.getStorageSync('dataDictionary') || []
		arr = data.filter((item)=>{
			return item.dicCode == value
		})
		return arr
	}

};
